
import pandas as pd
import pymysql

conn = pymysql.connect(
    host='127.0.0.1',
    user='root',
    passwd='12345678',
    port=3306,
    db='db_school',
    charset='utf8'
)

df = pd.read_excel("2020按季度学生成绩表.xlsx")
for idx, row in df.iterrows():
    print(f"process: {row.sno}, {row.course}")
    sql = f"""
        insert into student_grade
        (quarter, sno, course, grade)
        values ('{row.quarter}', '{row.sno}', '{row.course}', '{row.grade}') 
    """
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()

conn.close()